let app = getApp();
Page({
    data:{
         isCollect:false,
         header:{},
         userInfo:{},
          imgUrls: [
            {
              url:'http://qn.shebeib.com/11108e3e317028cf3d31fde3f3a133d.jpg'
            }
          ],
          indicatorDots: false,
          autoplay: true,
          interval: 5000,
          duration: 1000,
          obj:{

          },
          productList:[],
          imageList:[],
          showImageDetail:false,
          num:0
    },
    onClose:function(){
       this.setData({
           showImageDetail:false
           

        })
    },
    onLeft:function(){

      var num=this.data.num-1;
      if (num==-1) {
        num=this.data.imageList.length-1
      }

      this.setData({
        num:num
      })
    },
     onRight:function(){
      var num=this.data.num+1
       if (num==this.data.imageList.length) {
        num=0
      }
      this.setData({
        num:num
      })
    },
    showImage:function(e){
      console.log(e.currentTarget.dataset.code)
        this.setData({
           showImageDetail:true,
           imageList:e.currentTarget.dataset.code,
           num:e.currentTarget.dataset.num

        })
    },
    onLoad:function(options){
        // 生命周期函数--监听页面加载
        console.log("options.id")
        console.log(options);
        this.setData({
            equId:options.id,
            type:options.type
        })
          getApp().getUserInfo().then(res=>{
          var header={
                 'openid':res.openid, //公用请求头
                 'content-type': 'application/json'
             }
           wx.setStorageSync('userInfo', res)

           this.getDeviceDetail(options.id);
           this.isCollect(options.id);
           this.looK(options.id);
     })
       
       
    },
    looK:function (id) {
      var userInfo= wx.getStorageSync('userInfo');
      var url
      url=getApp().globalData.baseUrl + '/wx/equipment/browse/save'
       var _self=this;
         wx.request({
            url: url,
            method:"POST",
            data:{
              openid:userInfo.openid,
              equId:id
            },
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res)
            
            
           
         }
       })
        
    },
    getLeiSiDetail:function (type,province) {
       var userInfo= wx.getStorageSync('userInfo');
      var url
      url=getApp().globalData.baseUrl + '/wx/equipment/getList?status=20&type='+type+'&province='+province
       var _self=this;
         wx.request({
            url: url,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             console.log(res)
             _self.setData({
              productList:res.data.obj.list
             })
            
           
         }
       })
    },
    getDeviceDetail:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
         var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/equipment/detail?id='+id,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
             _self.getLeiSiDetail(res.data.obj.type,res.data.obj.province);
             console.log(res.data.obj)
             _self.setData({
                obj:res.data.obj
             })
            
           
         }
       })
    },
    onReady:function(){
        // 生命周期函数--监听页面初次渲染完成
       
    },
    onShow:function(){
      
      
    },
    onHide:function(){
        // 生命周期函数--监听页面隐藏
        
    },
    onUnload:function(){
        // 生命周期函数--监听页面卸载
       
    },
    onPullDownRefresh: function() {
        // 页面相关事件处理函数--监听用户下拉动作
      
    },
    onReachBottom: function() {
        // 页面上拉触底事件的处理函数
       
    },
    turnPage:function(){
        if (this.data.type) {

           wx.switchTab({
                  url: '../../pages/home/home'
           })
           return
        }
        
        wx.navigateTo({
            url:'/pages/sendSheBei/sendSheBei'
        })
    },
    callPhone:function(e){
         console.log(e.currentTarget.dataset.code)

        wx.makePhoneCall({
          phoneNumber: e.currentTarget.dataset.code //仅为示例，并非真实的电话号码
        })
    },

    //收藏
    collectequ:function () {
        ///wx/collectequ/user/delete
        ///wx/collectequ/user/save
      var userInfo= wx.getStorageSync('userInfo');
      console.log(123)
      var id=this.data.equId;
      var url='',type='';
      if (this.data.isCollect) {
        url='/wx/collectequ/user/delete';
        type="DELETE";
      }else{
        url='/wx/collectequ/user/save';
        type="GET";
      }
        var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+url+'?equId='+id+'&openid='+userInfo.openid,
            method:type,
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
           
             console.log(res.data.obj)
             _self.setData({
                obj:res.data.obj
             })
           
           
         }
       })
    },
    isCollect:function (id) {
        var userInfo= wx.getStorageSync('userInfo');
        var _self=this;
         wx.request({
            url:getApp().globalData.baseUrl+'/wx/collectequ/user?equId='+id+'&openid='+userInfo.openid,
            method:"GET",
            header: {
                'openid':userInfo.openid, //公用请求头
                'content-type': 'application/json'
            },
            success: function(res) {
           
             console.log(res)
             if (res.data.code==200) {

             }else{
                _self.setData({
                    isCollect:false
                })
             }
            
           
         }
       })
        // body...
    },
     eredarClick (e) { // 达人详情
      var id=e.currentTarget.dataset.code;
    
      wx.navigateTo({
            url: '/pages/eredarDetail/eredarDetail?openid='+id
        })
    },
    onShareAppMessage:function(){
      var str='';
      if(this.data.obj.price==0){
          str='面议'
      }else{
          str=this.data.obj.price+'万'
      }

         return {
              title: this.data.obj.title+'--'+str+'【'+this.data.obj.city+'】',
              path: '/pages/deviceDetail/deviceDetail?id='+this.data.equId+"&type=share"
            }
    },
   
})